

#pragma once

#include "cocos2d.h"
USING_NS_CC;

#include "type.h"
#include "equipment.h"
#include "formation.h"

#include <vector>
#include <map>
using namespace std;

namespace cocos2d {
	class CCSkeletalSprite;
}

class Unit;
class EquipmentDetailLayer;

enum class CollectionSceneTouchPlace {
	blank,
	tab_button,
	equipment_view,
	equipment_item,
	dragging_equipment,
};

class CollectionScene : public CCScene, public CCTargetedTouchDelegate, public CCKeypadDelegate {
public:
	CollectionScene();
	virtual ~CollectionScene();

    CREATE_FUNC(CollectionScene);

private:
	virtual bool init();

	void createTabButtons();
	void createEquipments();
	void createSmeltingPad();

	void switchEquipmentView();
	void scrollEquipmentView(float distance);
	void handleDroppingEquipment(const CCPoint& pt);
	void showEquipmentDetail();

	void onClose(CCObject* sender);

	virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
	virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
	virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
	virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);

	virtual void keyBackClicked();
	virtual void keyMenuClicked();

	virtual void onExit();
	virtual void onEnter();

private:
	CCLayer* _layer;
	CCLayer* _layerEquipments[(int)EquipmentType::count];
	EquipmentDetailLayer* _layerEquipmentDetail;

	float _arrItemRows[(int)EquipmentType::count];

	CCSprite* _tabButtons[(int)EquipmentType::count];

	CollectionSceneTouchPlace _touchPlace;

	int _selectedTabIndex;
	int _touchedTabButtonIndex;
	int _touchedEquipmentIndex;

	CCPoint _draggingStartPos;

	vector<CCSprite*> _arrCreatureSprites;
	vector<CCSprite*> _arrWeaponSprites;
	vector<CCSprite*> _arrArmorSprites;
	vector<CCSprite*> _arrShieldSprites;
	vector<CCSprite*> _arrSpecialSprites;

	vector<CCSprite*>* _arrSprites[(int)EquipmentType::count];

	CCSprite* _draggingEquipment;

	CCLabelTTF* _labelPoints;

};
